package com.turman.builibrary.refresh;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.turman.blibrary.util.BDisplayUtil;

/**
* 下拉刷新头部视图
* @author buobao
* @since 2024/3/13 13:29
*/
public abstract class BOverview extends FrameLayout {
    public enum RefreshState {
        //初始状态
        STATE_INIT,
        //头部显示状态
        STATE_VISIBLE,
        //超出可刷新距离的状态
        STATE_REFRESHING,
        //超出可刷新距离的状态
        STATE_OVER,
        //超出刷新位置松开手后的状态
        STATE_OVER_RELEASE
    }

    protected RefreshState state = RefreshState.STATE_INIT;
    //触发下拉刷新束腰的最小高度
    public int mPullRefreshHeight;
    //最小阻尼
    public float minDamp=1.6f;
    //最大阻尼
    public float maxDamp=2.2f;
    public BOverview(@NonNull Context context) {
        this(context,null);
    }

    public BOverview(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public BOverview(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        preInit();
    }

    protected void preInit() {
        mPullRefreshHeight = BDisplayUtil.dp2px(66f,getResources());
        post(()-> getLayoutParams().height = mPullRefreshHeight);
        init();
    }

    public abstract void init();
    protected abstract void onScroll(int scrollY,int pullRefreshHeight);

    /**
     * 显示Overlay
     */
    protected abstract void onVisible();

    /**
     * 超过Overlay高度,释放加载
     */
    public abstract void onOver();

    /**
     * 开始刷新
     */
    public abstract void onRefresh();

    /**
     * 刷新完成
     */
    public abstract void onRefreshFinished();

    public void setState(RefreshState state) {
        this.state = state;
    }

    public RefreshState getState() {
        return state;
    }
}
























